package com.wlyuan.open.domain.client.respository;

import com.wlyuan.open.vo.OpenClientDetailVO;
import com.wlyuan.redisson.repository.BaseCacheRepository;
import com.wlyuan.redisson.repository.CacheOptions;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yuanjie
 */
@Service
public class OpenClientCacheRepository extends BaseCacheRepository<String, OpenClientDetailVO> {
    public OpenClientCacheRepository(RedissonClient redissonClient, JsonJacksonCodec jsonJacksonCodec,
                                     OpenClientCacheResolver cacheResolver) {
        super(new CacheOptions("PC::CACHE::OPEN::CLIENT", 24 * 60L, 1000),
                redissonClient, jsonJacksonCodec, cacheResolver);
    }

    @Override
    public void remove(String appId) {
        if (StringUtils.isNotBlank(appId)) {
            super.remove(appId);
        }
    }

    public void removeAll(List<String> appIds) {
        if (CollectionUtils.isEmpty(appIds)) {
            return;
        }
        appIds.stream().forEach(this::remove);
    }
}
